{extend name="$base_mall" /}
{block name="resources"}
<link rel="stylesheet" type="text/css" href="WAP_CSS/mill_common.css">
<link rel="stylesheet" type="text/css" href="WAP_CSS/verification_code.css">
<style>
	.cf-tab-item{
		width: 50% !important;
	}
</style>
{/block}
{block name="main"}
<div class="main_content">
	<div class="cf-container ns-border-color-gray">
		<ul class="cf-content">
			<li class="cf-tab-item selected ns-border-color ns-text-color">登录密码</li>
			<li class="cf-tab-item ns-text-color-gray">支付密码</li>
		</ul>
	</div>
	<div class="password">
		<div class="input-div">
			<span>原密码</span>
			<input type="password" id="old_password" placeholder="请输入您的原始登密码" value="">
		</div>
		<div class="line" style="height: 0px"></div>
		<div  class="input-div">
			<span>新密码</span>
			<input type="password" id="password" placeholder="请输入您的新密码" value="">
		</div>
		<div class="line" style="height: 0px"></div>
		<div  class="input-div">
			<span>确认密码</span>
			<input type="password" id="cfm_password" placeholder="请再次输入您的新密码" value="">
		</div>
		<div style="background-color: white;padding: 20px 20px;box-sizing: border-box">
			<button class="long-btn" onclick="act_modify()">立即修改</button>
		</div>
	</div>

	<div class="pay_password" style="display: none">
		<div class="input-div">
			<span>原支付密码</span>
			<input type="password" id="old_pay_password" placeholder="请输入您的原始登密码" value="">
		</div>
		<div class="line" style="height: 0px"></div>
		<div  class="input-div">
			<span>新支付密码</span>
			<input type="password" id="pay_password" placeholder="请输入您的新密码" value="">
		</div>
		<div class="line" style="height: 0px"></div>
		<div  class="input-div">
			<span>确认支付密码</span>
			<input type="password" id="cfm_pay_password" placeholder="请再次输入您的新密码" value="">
		</div>
		<div style="background-color: white;padding: 20px 20px;box-sizing: border-box">
			<button class="long-btn" onclick="act_cfm_modify()">立即修改</button>
		</div>
	</div>

</div>
{/block}
{block name="footer"}{/block}
{block name="script"}
<script>
	$(function(){
		$('.cf-container .cf-tab-item').click(function () {
			var i = $(this).index();
			$('.cf-container .cf-tab-item').removeClass('selected ns-border-color ns-text-color').addClass("ns-text-color-gray");
			$(this).addClass('selected ns-border-color ns-text-color').removeClass("ns-text-color-gray");
			if(i === 0){
				$(".pay_password").hide();
				$(".password").show();
			}else{
				$(".pay_password").show();
				$(".password").hide();
			}
		});
	});

	function act_modify() {
		var oldpassword = $("#old_password").val();
		var newpassword = $("#password").val();
		var newpassword2 = $("#cfm_password").val();
		var reg = /^[\@A-Za-z0-9\!\#\$\%\^\&\*\.\~]{6,16}$/;
		if (oldpassword.length == 0) {
			toast('原始密码必须输入');
			return false;
		}
		if (!reg.test(newpassword)) {
			toast('新密码输入错误，必须大于6位', "warning");
			return false;
		}
		if (newpassword2 != newpassword) {
			toast('两次输入密码不一致');
			return false;
		}
		api('System.Member.modifyPassword', {
			"new_password": newpassword,
			"old_password": oldpassword
		}, function (res) {
			if (res['data'] > 0) {
				toast('密码修改成功');
				backAndClose();
			} else {
				toast('原密码输入错误');
			}
		});
	}

	function act_cfm_modify() {
		var oldpassword = $("#old_pay_password").val();
		var newpassword = $("#pay_password").val();
		var newpassword2 = $("#cfm_pay_password").val();
		var reg = /^[\@A-Za-z0-9\!\#\$\%\^\&\*\.\~]{6,16}$/;
		if (oldpassword.length == 0) {
			toast('原支付密码必须输入');
			return false;
		}
		if (!reg.test(newpassword)) {
			toast('新支付密码输入错误，必须大于6位', "warning");
			return false;
		}
		if (newpassword2 != newpassword) {
			toast('两次支付输入密码不一致');
			return false;
		}
		api('System.Member.modifyPayPassword', {
			"new_password": newpassword,
			"old_password": oldpassword
		}, function (res) {
			if (res['data'] > 0) {
				toast('支付密码修改成功');
				backAndClose();
			} else {
				toast('原支付密码输入错误');
			}
		});
	}
</script>
{/block}